package main

import (
	"fmt"
	"os"
)

func do() error {
	f, err := os.OpenFile("book.txt",os.O_APPEND|os.O_WRONLY,os.ModeAppend)
	if err != nil {
		return err
	}
	c := []byte("sdwaer")
	_, err = f.Write(c)

	if err !=nil{
		fmt.Println(err)
	}

	defer func() {
		if err := f.Close(); err != nil {
			fmt.Printf("defer close book.txt err %v\n", err)
		}
	}()

	// ..code...

	f2, err := os.Open("another-book.txt")
	if err != nil {
		return err
	}
	if f2 != nil {
		defer func() {
			if err := f2.Close(); err != nil {
				fmt.Printf("defer close another-book.txt err %v\n", err)
			}
		}()
	}

	return nil
}

func main() {
	_ = do()
}
